<?php
//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有！                         |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                       |
// +------------------------------------------------------------------------+
// | Author: songaimin@clcw.com.cn  Blog:http://blog.csdn.net/samxx8        |
// +------------------------------------------------------------------------+
//
namespace AuctionCore\Account;

use AuctionCore\Common\PhpRedis;

/**
* 唯一登录处理类
* @author       Administrator
*/
class UniqLogin{

    private $crypt_key = 'clcw_uniq_login';

    /**
    * @param $uid int 登录用户id或用户名
    * @param $expire string 登录有效期
    * @return mixed  检查唯一登录的key
    */
    public function update($uid,$expire=false){
        $redis = new PhpRedis();
        $now = time();
        if(!$expire){
            $expire = (104400-($now%104400));
        }
        $uniq_login_token = FrontUser::create_access_token($uid);
        $redis->set($this->get_uniq_login_key($uid),$uniq_login_token,$expire);
        return $uniq_login_token;
    }

    //唯一登录检查
    public function check($uid,$uniq_login_token){
        if(!$uid || !$uniq_login_token)
            return false;
        $redis = new PhpRedis();
        $redis_uniq_login_token = $redis->get($this->get_uniq_login_key($uid));
        return $redis_uniq_login_token == $uniq_login_token;
    }

    private function get_uniq_login_key($uid){
        $arr = ['uid'=>$uid];
        return getRedisKeyByCode('REDIS_KEY','100021',$arr);
    }
   
}

?>